package activiti;

/**
 * @Author: 蔡翔
 * @Date: 2019/8/30 14:15
 * @Version 1.0
 */

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;

import java.io.InputStream;
import java.util.zip.ZipInputStream;

/**
 * 流程定义部署
 *
 * 流程部署是最先要做的，部署好请假流程（总的）以后，下次就可以新建一个张三流程、李四流程，王五流程了。
 * */
public class ActivitiDeployment {
    //流程部署的 4 个步骤
    public static void main(String[] args) {
        //1.创建ProcessEngine对象: 用defaultProcessEngine 要满足两个条件。
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        //2.得到RepositoryService实例
        RepositoryService repositoryService = processEngine.getRepositoryService();

        /*//3.转化出ZipInputStream流对象
        InputStream inputStream = ActivitiDeployment.class.getClassLoader().getResourceAsStream("bpmn.zip");
        //将inputstream流转化为ZipInutStream
        // activiti 初始化数据库的时候，database要先创建出来。
        ZipInputStream zipInputStream = new ZipInputStream(inputStream);
        Deployment deployment = repositoryService.createDeployment()
                                    .addZipInputStream(zipInputStream)
                                    .name("请假单申请流程")
                                    .deploy();*/

        //3.进行部署
        Deployment deployment = repositoryService.createDeployment().addClasspathResource("holiday.bpmn")  //添加bpmn资源
                .addClasspathResource("holiday.png")
                .name("请假流程。")
                .deploy();//部署

        //4.输出部署的一些信息
        System.err.println("deploymentName:"+deployment.getName());
        System.err.println("deploymentId:"+deployment.getId());
    }
}
